package com.daidai.app;

import com.daidai.domain.User;
import com.daidai.impl.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class App1 {
    public static void main(String[] args) throws IOException {

        InputStream inputStream = Resources.getResourceAsStream("SqlMapperConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession(true);

        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        List<User> users = userMapper.selectAll();
        System.out.println(users);

        User user = userMapper.selectUserById(2);
        System.out.println(user);

//        userMapper.insertUser(new User(1, "zhangsan", "000000"));

//        userMapper.updateUser(new User(1, "wangwu", "123456"));

        userMapper.deleteUser(1);

    }
}
